﻿using System;
using System.Collections.Generic;

namespace StockFinder.Model
{
    public class Trade
    {
        public string Symbol { get; set; }
        public DateTime EntryDate { get; set; }
        public DateTime ExitDate { get; set; }
        public decimal EntryPrice { get; set; }
        public decimal ExitPrice { get; set; }
        public decimal HardStopLoss { get; set; }
        public decimal TrailingStopLoss { get; set; }
        public decimal HighestClose { get; set; }

        /// <summary>
        /// Place to add any details of the state of the stock at entry
        /// </summary>
        public Dictionary<string, decimal> StateAtEntry = new Dictionary<string, decimal>();

        /// <summary>
        /// Gets/sets flag for whether this position is open i.e. in flow
        /// </summary>
        public bool IsOpen { get; set; }        

        public int DaysInPosition
        {
            get { return (ExitDate - EntryDate).Days; }
        }

        public decimal PnL
        {
            get
            {
                return Math.Round(((ExitPrice - EntryPrice) / EntryPrice) * 100, 2);
            }
        }

        public decimal R
        {
            get
            {
                var initialR = EntryPrice - HardStopLoss;

                var actualR = EntryPrice - ExitPrice;

                var r = (actualR / initialR);

                return (Math.Round(r, 2) * -1);
            }            
        }
    }
}
